package com.young.shop_admin.controller;

import com.young.shop_admin.pojo.entity.Order;
import com.young.shop_admin.pojo.qo.SelectDateQO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/selectOrderByDate")
public class SelectOrderByDateController extends BaseController{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //跨域
        resp.setHeader("Access-Control-Allow-Origin","http://localhost:63342");
        //获取前端时间
        SelectDateQO dateQO = convertParamsToEntity(req, SelectDateQO.class);
        String beforeDate = dateQO.getBeforeDate();
        String afterDate = dateQO.getAfterDate();
        System.out.println("beforeDate"+beforeDate);
        //通过时间查询订单
        try {
            List<Order> orderList = BaseController.orderList.selectOrderListByDate(beforeDate, afterDate);
            writerSuccessResult(orderList,resp);
        }catch (RuntimeException e){
            String errorMsg = e.getMessage();
            writerErrorResult(errorMsg, resp);
        }
    }
}
